package com.situ.mall.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.common.util.PageResult;
import com.situ.mall.mapper.OrderMapper;
import com.situ.mall.pojo.entity.Order;
import com.situ.mall.pojo.entity.OrderItem;
import com.situ.mall.pojo.query.OrderQuery;
import com.situ.mall.pojo.vo.OrderCountVO;
import com.situ.mall.pojo.vo.OrderVO;
import com.situ.mall.pojo.vo.OrderVOAdmin;
import com.situ.mall.pojo.vo.SalesVolumeVO;
import com.situ.mall.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public PageResult selectByPage(OrderQuery orderQuery) {
        //使用PageHelper开启分页
        PageHelper.startPage(orderQuery.getPage(), orderQuery.getLimit());
        //开启分页之后 LIMIT offset,pageSize 这个代码PageHelper帮我们做了
        List<OrderVOAdmin> list = orderMapper.selectByPageAdmin(orderQuery);
        //查找总数量PageHelper会自动帮我们完成
        //int totalCount = userMapper.selectTotalCount(userQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount, list);
    }

    @Override
    public void updateStatus(Order order) {
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public void updateIsDeleted(Order order) {
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public List<OrderItem> orderItemByOrderNo(Long orderNo) {
        return orderMapper.orderItemByOrderNo(orderNo);
    }

    @Override
    public Order orderByOrderNo(Long orderNo) {
        return orderMapper.selectByPrimaryKey(orderNo);
    }

    @Override
    public void deleteById(Long orderNo) {
        orderMapper.deleteByPrimaryKey(orderNo);
    }

    @Override
    public List<SalesVolumeVO> TotalSalesByDay() {
        return orderMapper.TotalSalesByDay();
    }

    @Override
    public Integer totalCost() {
        return orderMapper.totalCost();
    }

    @Override
    public List<OrderCountVO> selectTotalOrder() {
        return orderMapper.selectTotalOrder();
    }
}
